<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>新增模型分组</title>
    <link rel="stylesheet" href="../../../component/pear/css/pear.css"/>
    <link rel="stylesheet" href="../../../admin/css/reset.css"/>
</head>
<body>

<form class="layui-form" action="" lay-filter="create-data-form">

    <div class="mainBox">
        <div class="main-container mr-5">
            <div class="layui-form-item">
                <label class="layui-form-label required">类别名称</label>
                <div class="layui-input-block">
                    <input type="text" name="name" required lay-verify="required" autocomplete="off" class="layui-input" placeholder="请输入名称">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">排序</label>
                <div class="layui-input-block">
                    <input type="number" name="sort" min="0"   autocomplete="off" class="layui-input"  value="10">
                </div>
            </div>

            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">备注</label>
                <div class="layui-input-block">
                    <textarea placeholder="" class="layui-textarea" name="remarks"></textarea>
                </div>
            </div>
        </div>
    </div>

    <div class="bottom">
        <div class="button-container">
            <button type="submit" class="pear-btn pear-btn-primary pear-btn-md" lay-submit=""
                    lay-filter="save">
                保存
            </button>
            <button type="reset" class="pear-btn pear-btn-md">
                重置
            </button>
        </div>
    </div>
</form>
<script src="../../../component/layui/layui.js"></script>
<script src="../../../component/pear/pear.js"></script>
<script src="../../../lms/base64.js"></script>
<script src="../../../lms/common.js"></script>
<script src="../../../lms/permission.js"></script>
<script src="../../../lms/config.js"></script>
<script>


    const PRIMARY_KEY = "id";
    const RESTFUL_API = lms_config.api_url + "/adminapi/wf/category";

    // 字段设置
    layui.use(["common", "popup", "form", "jquery"], function () {

        let table = layui.table;
        let common = layui.common;
        let popup = layui.popup;
        let form = layui.form;
        let method = 'POST';
        let $ = layui.jquery;


        if (getQueryString('operation') == 'add') {
            let pid = getQueryString('pid')
        }

        if (getQueryString('operation') == 'edit') {
            method = 'PUT'
            get()
            layui.$("button[type='reset']").click(function () {
                location.reload();
            })
            form.render()
        }


        /**
         * 表单提交
         */
        form.on("submit(save)", function (data) {
            layui.$.ajax({
                url: method == 'POST' ? RESTFUL_API : RESTFUL_API + '/' + getQueryString(PRIMARY_KEY),
                type: method,
                dateType: "json",
                contentType: 'application/json',
                data: JSON.stringify(data.field),
                success: function (ret) {
                    if (ret.status == 200) {
                        popup.success(ret.msg, function () {
                            parent.refreshTable();
                            parent.layer.close(parent.layer.getFrameIndex(window.name));
                        });
                    } else {
                        popup.failure(ret.msg);
                    }
                }
            });
            return false;
        });

        function get() {
            layui.$.ajax({
                    url: RESTFUL_API + '/' + getQueryString(PRIMARY_KEY),
                    method: 'GET',
                    dataType: 'JSON',
                    success: function (ret) {
                        if (ret.status === 200) {
                            let data = ret.data;
                            form.val("create-data-form", data)
                            form.render();
                        }
                    },
                    error: function (ret) {
                        alert("出错" + ret.status + "：" + ret.responseText);
                    }
                }
            );
        }

    });


</script>

</body>
</html>
